﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace netsoul
{
    public partial class FrmParam : Form
    {
        public FrmParam()
        {
            InitializeComponent();
        }

        private void FrmParam_Load(object sender, EventArgs e)
        {
                this.txt_location.Text = Properties.Settings.Default.location;
                this.txt_server.Text = Properties.Settings.Default.server;
                this.txt_userdata.Text = Properties.Settings.Default.data;
                this.cbox_save_password.Checked = Properties.Settings.Default.save_password;
                if (Properties.Settings.Default.save_param == true)
                {
                    this.txt_login.Text = Properties.Settings.Default.username;
                    if (Properties.Settings.Default.save_password == true)
                        this.txt_password.Text = Properties.Settings.Default.password;
                }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (this.txt_login.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "Error : You haven't specified a login to log into the netsoul network.", "Error",  MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.txt_password.Text.Trim().Length == 0)
                MessageBox.Show(this, "Warning : You haven't specified a password to log into the netsoul network.\r\nWould you enter a password?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            if (this.txt_server.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "Error : You haven't specified the netsoul server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Properties.Settings.Default.username = this.txt_login.Text.Trim();
            if (cbox_save_password.Checked == true)
            {
                Properties.Settings.Default.save_password = true;
                Properties.Settings.Default.password = this.txt_password.Text.Trim();
            }
            Properties.Settings.Default.location = this.txt_location.Text.Trim();
            Properties.Settings.Default.data = this.txt_userdata.Text.Trim();
            Properties.Settings.Default.save_param = true;
            Properties.Settings.Default.Save();
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
